package com.probiz.estoresa.catalog.web.action;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.validation.BindException;
import org.springframework.web.servlet.ModelAndView;

import com.probiz.estore.catalog.service.GiftCategoryManager;
import com.probiz.estore.common.model.catalog.GiftCategory;
import com.probiz.estore.core.controller.GenericStoreAdminController;

public class GiftCategorySelectorController extends	GenericStoreAdminController<GiftCategory> {
	private GiftCategoryManager giftCategoryManager = null;


	public void setGiftCategoryManager(GiftCategoryManager giftCategoryManager) {
		this.giftCategoryManager = giftCategoryManager;
	}

	/*
	 * (non-Javadoc)
	 * @see com.probiz.estore.core.controller.GenericStoreAdminController#getEntityName(java.lang.Object)
	 */
	@Override
	protected String getEntityName(GiftCategory entity) {
		return entity.getGiftCategoryName();
	}


	/*
	 * (non-Javadoc)
	 * @see com.probiz.estore.core.controller.GenericStoreAdminController#initController()
	 */
	@Override
	protected void initController() throws Exception {
		mgr = giftCategoryManager;
	}

	

	@Override
	protected void preSave(HttpServletRequest request, GiftCategory entity,	BindException errors) {
		
	}

	
	public ModelAndView defaultAction(HttpServletRequest request,
			HttpServletResponse response) {
		ModelAndView mv = new ModelAndView("catalog/giftCategorySelector");
		GiftCategory treeRoot = giftCategoryManager.getById(1);
		Set<GiftCategory> categorySet = treeRoot.getChildren();
		List<GiftCategory> categoryList = new ArrayList<GiftCategory>();
		categoryList.addAll(categorySet);
		mv.addObject("categoryList", categoryList);
		mv.addObject("treeRoot", treeRoot);
		return mv;
	}
	
	
	
}
